﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using Microsoft.Practices.EnterpriseLibrary.Data;

namespace BOHVote.Core
{
    public class DatabaseProvider
    {
        private static Hashtable createdDatabases;

        public static Database CreateDatabase(string connectionKey)
        {
            Database db;

            if (createdDatabases == null)
            {
                createdDatabases = new Hashtable();
            }

            if (connectionKey == null)
            {
                connectionKey = string.Empty;
            }

            if (createdDatabases.Contains(connectionKey))
            {
                db = (Database)createdDatabases[connectionKey];
            }
            else
            {
                if (connectionKey.Length == 0)
                {
                    db = DatabaseFactory.CreateDatabase();
                }
                else
                {
                    db = DatabaseFactory.CreateDatabase(connectionKey);
                }
                createdDatabases.Add(connectionKey, db);
            }
            return db;
        }
    }
}
